<template>
  <el-card>
    <div slot="header" class="header">
      <div class="category-header">
        <span>销售额类别占比</span>
        <el-radio-group v-model="value" size="mini" class="radio">
          <el-radio-button label="全部渠道"></el-radio-button>
          <el-radio-button label="线上"></el-radio-button>
          <el-radio-button label="门店"></el-radio-button>
        </el-radio-group>
      </div>
    </div>
    <div>
      <div class="charts" ref="charts"></div>
    </div>
  </el-card>
</template>

<script>
export default {
  name: "Category",
  data() {
    return {
      value: "全部渠道",
    };
  },
  mounted() {
    let mycharts = this.$echarts.init(this.$refs.charts);
    mycharts.setOption({
      title: {
        text: "联盟广告",
        subtext: 484,
        top: "center",
        left: "center",
      },
      tooltip: {
        trigger: "item",
      },
      //  饼图切换不同的类型
      // legend: {
      //   top: "5%",
      //   left: "center",
      // },
      series: [
        {
          name: "销售额占比",
          type: "pie",
          radius: ["40%", "70%"],
          avoidLabelOverlap: false,
          itemStyle: {
            borderRadius: 10,
            borderColor: "#fff",
            borderWidth: 2,
          },
          label: {
            show: true,
            position: "outside",
          },
          // 放大
          // emphasis: {
          //   label: {
          //     show: true,
          //     fontSize: 40,
          //     fontWeight: "bold",
          //   },
          // },
          // 饼图的线
          labelLine: {
            show: true,
          },
          data: [
            { value: 1048, name: "搜索引擎" },
            { value: 735, name: "直接访问" },
            { value: 580, name: "邮件营销" },
            { value: 484, name: "联盟广告" },
            { value: 300, name: "视频广告" },
          ],
        },
      ],
    });

    // 给图表绑定事件
    mycharts.on("mouseover",  function (params) {
      // 此处的params就是你鼠标移入的那条数据
      // console.log(params);
      const {name,value} = params.data
      mycharts.setOption({
        title:{
          text:name,
          subtext:value
        }
      })
    });
  },
};
</script>

<style scoped>
.category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 0 11px;
}
.header {
  border-bottom: 1px solid #eee;
  line-height: 100%;
}
.radio {
  margin-top: -5px;
}
.charts {
  width: 100%;
  height: 300px;
}
</style>